package com.nbsaas.boot.solution.rest.convert;

import com.nbsaas.boot.solution.data.entity.Solution;
import com.nbsaas.boot.solution.api.domain.request.SolutionRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.jpa.data.entity.User;
            import com.nbsaas.boot.solution.data.entity.SolutionCatalog;

/**
* 解决方案请求对象转换成实体对象
*/

public class SolutionEntityConvert  implements Converter<Solution, SolutionRequest> {

    @Override
    public Solution convert(SolutionRequest source) {
        Solution result = new Solution();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
                    if(source.getSolutionCatalog()!=null){
                    SolutionCatalog solutionCatalog =new SolutionCatalog();
                    solutionCatalog.setId(source.getSolutionCatalog());
                    result.setSolutionCatalog(solutionCatalog);
                    }
        return result;
    }
}

